//ajaxA 返回数据之后，启动 ajaxB，等B返回数据之后，再启动 ajaxC
function fn() {
    let xhrA = new XMLHttpRequest();
    xhrA.open("get", "urlA");
    xhrA.send();
    xhrA.onreadystatechange = function () {
        if (xhrA.status == 200 && xhrA.readyState == 4) {
            //DOM操作
            xhrA.responseText
            let xhrB = new XMLHttpRequest();
            xhrB.open("get", "urlB");
            xhrB.send();
            xhrB.onreadystatechange = function () {
                if (xhrB.status == 200 && xhrB.readyState == 4) {
                    //DOM操作
                    xhrB.responseText
                    let xhrC = new XMLHttpRequest();
                    xhrC.open("get", "urlC");
                    xhrC.send();
                    xhrC.onreadystatechange = function () {
                        if (xhrC.status == 200 && xhrC.readyState == 4) {
                            //DOM操作
                            xhrC.responseText
                        }
                    }
                }
            }
        }
    }
}

//改promise
//promise 封装一个ajax
function CreatePromiseAjax(url) {
    let p = new Promise((resolve, reject) => {
        let xhrA = new XMLHttpRequest();
        xhrA.open("get", url);
        xhrA.send();
        xhrA.onreadystatechange = function () {
            if (xhrA.readyState == 4) {
                if (xhrA.status == 200) {
                    //DOM操作
                    resolve(xhrA.responseText)
                } else {
                    reject("失败")
                }
            }
        }
    })
    return p;
}
let pA = CreatePromiseAjax("urlA");
console.log(123);



pA.then(() => {
    //
    let pB = CreatePromiseAjax("urlB");
    return pB;
}).then(() => {
    return CreatePromiseAjax("urlC");
}).then(() => {

})


// 
async function afn() {
    let dataA = await CreatePromiseAjax("urlA");
    let dataB = CreatePromiseAjax("urlB");
    let dataC = CreatePromiseAjax("urlC");

}
pA.then(() => { }, () => { })


pA.then(() => {
    console.log(1);
})
pA.then(() => {
    console.log(2);
})

pA.then(() => {
    console.log(3);
})

//状态已经变成了成功
pA.then(() => {
    console.log(44);
}).catch((ex) => {

})


try {
    let a = 210;
    let a = 100;
} catch (e) {

}

